
	//var data_columns = ['id','name','count','updateAt'];
	//var action_columns = ['重命名','删除']
	//init_page(1,20);//当前页，每页个数
	var curr_url="";
	var data_columns = [];
	var action_columns = [];
	var click_function;
	var query_type;
	var has_input = false;
	function set_has_input(f_has_input) {
		has_input = f_has_input;
	}
	function set_query_type(f_type) {
		query_type = f_type;
	}
	function set_function(my_function) {
		click_function = my_function;
	}
	function set_url(f_url) {
		curr_url = f_url;
	}
	function set_data_columns(f_data_columns) {
		data_columns = f_data_columns;
	}
	function set_action_columns(f_action_columns) {
		action_columns = f_action_columns;
	}
	function init_page(curr_page,curr_size) {
		get_datas(curr_page,curr_size,curr_url);
		
	}
	function get_datas(f_page_number,f_page_size,url) {
		var jsondata = {
			'pageNumber' : f_page_number,
			'pageSize' : f_page_size
		}
		if(query_type!=null) {
			jsondata['quey_type'] = query_type;
		}
		curr_page = f_page_number
		curr_size = f_page_size
		$.ajaxSetup({   
            async : false  
        }); 
		$.post(url,jsondata,
		function(data,status){
			console.log(data);
			show_datas(data.entries);
			show_pages(data.page,data.totalPages)
		});
		click_function();
	}
	function show_datas(datas) {
		$('#table-all').empty();
		for(var i in datas) {
			if(!has_input) {
				common_addtd(datas[i]);
			}else {
				common_addtd_input(datas[i],parseInt(i)+1);
			}
		}
	}
	function common_addtd(data){
		
		var tr = document.createElement("tr");
		tr.setAttribute('id','tr-id-'+data[data_columns[0]]);//source-id//WX//FILE
		for(var i=1;i<data_columns.length;i++) {
			var td = document.createElement("td");
			td.setAttribute("class","patent-data-table show-column"+i);
			td.setAttribute("id","td-"+i+"-id-"+data[data_columns[0]]);
			td.innerHTML=convert_data(data_columns[i],data[data_columns[i]],data);
			tr.appendChild(td);
		}
		var td_action = document.createElement("td");
		td.setAttribute("class","patent-data-table show-column-last");
		var actionHTML = "";
		for(var i in action_columns) {
			actionHTML=actionHTML+convert_action_data(action_columns[i],data);
		}
		td_action.innerHTML = convert_data('action',actionHTML,data);
		tr.appendChild(td_action);
		$('#table-all').append(tr);
	}
	function common_addtd_input(data,index){
		console.log(index)
		var tr = document.createElement("tr");
		tr.setAttribute('id','tr-id-'+data[data_columns[0]]);//source-id//WX//FILE
		var td_input = document.createElement("td");
		td_input.setAttribute("class","patent-data-table show-column");
		td_input.setAttribute("id","td-"+0+"-id-"+data[data_columns[0]]);
		td_input.innerHTML="<input type='checkbox' id='selected-query-"+data[data_columns[0]]+"'>";
		tr.appendChild(td_input);
		var td_index = document.createElement("td");
		td_index.setAttribute("class","query-index patent-data-table show-column"+0);
		td_index.setAttribute("id","td-"+0+"-id-"+data[data_columns[0]]);
		td_index.innerHTML="#"+index;
		tr.appendChild(td_index);
		
		for(var i=1;i<data_columns.length;i++) {
			var td = document.createElement("td");
			if(data_columns[i]=="content") {
				td.setAttribute("class","query-value patent-data-table show-column"+i);
			}else {
				td.setAttribute("class","patent-data-table show-column"+i);
			}
			
			td.setAttribute("id","td-"+i+"-id-"+data[data_columns[0]]);
			td.innerHTML=convert_data(data_columns[i],data[data_columns[i]],data);
			tr.appendChild(td);
		}
		var td_action = document.createElement("td");
		td.setAttribute("class","patent-data-table show-column-last");
		var actionHTML = "";
		for(var i in action_columns) {
			actionHTML=actionHTML+convert_action_data(action_columns[i],data);
		}
		td_action.innerHTML = convert_data('action',actionHTML,data);
		tr.appendChild(td_action);
	
		$('#table-all').append(tr);
	}
	function convert_data(data_name,data_content,data) {
		var div_start = "<div class = 'table-content' data-container='body' data-toggle='popover' data-placement='bottom' >";
		var div_end = "</div>";
		var res = data_content;
		if(data_name=="updateAt") {
			res = new Date(data_content).toLocaleDateString();
		}else if(data_name=="lastAnalysis") {
			if(!!data_content) {
				res = new Date(data_content).toLocaleDateString();
			}else {
				res = "未标引";
			}
		}else if(data_name=="createAt") {
			res = new Date(data_content).toLocaleDateString();
		}
		
		res = div_start+res+div_end;
		return res;
	}
	
	function convert_action_data(action_data,data) {
		var res = action_data;
		if(action_data=="保存") {
			if(!!data['type']) {
				if(data['type']==1) {
					res = "已保存";
				}
			}
		}
		if(action_data=="标引") {
			if(!!data['lastAnalysis']) {
				res = "重新标引";
			}
		}
		if(action_data=="报告下载") {
			if(!!data['reportPath']) {
				res = "<a href='/report/download/wordres?depot_id="+data[data_columns[0]]+"'>报告下载</a>";
			}else {
				res = "";
			}
		}
		
		res = "<span class='glyphicon action-span'>"+res+"</span>";
		return res;
	}
	function show_pages(page,totalPages) {
		$("#page_all").twbsPagination({
			onPageClick:function pageselectCallback(event,page_index){
				jump_page(page_index);
			},
			initiateStartPageClick:false,
			totalPages:totalPages,
			visiblePages:5,
			first:'首页',
			last:'尾页',
			prev:'上一页',
			next:'下一页',
	    });
	}
	function jump_page(f_curr_page) {
		get_datas(f_curr_page,curr_size,curr_url);
	}
	function get_curr_span_id(span) {
		var id = span.parent().parent().parent().attr('id');
		return id;
	}
	